package org.dsun.json.bean;

/**
 * 是不是这样的夜晚，你才会这样的想起我！
 * @author donga
 * @version 1.2
 * @since 2011-8-18
 */
public class JsonValue {
	
	protected Object value;
	
	public JsonValue(){
		
	}
	
	public JsonValue(ValueList value){
		this.value=value;
	}
	
	public JsonValue(JsonObject value){
		this.value=value;
	}
	
	public JsonValue(String value){
		this.value=value;
	}
	
	public JsonValue(int value){
		this.value=value;
	}
	
	public JsonValue(double value){
		this.value=value;
	}
	
	public JsonValue(boolean value){
		this.value=value;
	}
	
	public Object getValue() {
		return value;
	}
//	public void setValue(Object value) {
//		this.value = value;
//	}
	
	public void setValue(ValueList value){
		this.value = value;
	}
	
	public void setValue(JsonObject value){
		this.value = value;
	}
	
	public void setValue(String value){
		this.value = value;
	}
	
	public void setValue(int value){
		this.value = value;
	}
	
	public void setValue(double value){
		this.value = value;
	}
	
	public void setValue(boolean value){
		this.value = value;
	}
	
	@Override
	public String toString(){
		if(this.value==null){
			return "null";
		}
		if(this.value instanceof String){
			value=((String) value).replace("\"", "\\\"");
			value=((String) value).replace("\\", "\\\\");
//			value=((String) value).replace("/", "\\/");
			value=((String) value).replace(new Character((char) 8).toString(), "\\b");
			value=((String) value).replace(new Character((char) 12).toString(), "\\f");
			value=((String) value).replace(new Character((char) 10).toString(), "\\n");
			value=((String) value).replace(new Character((char) 13).toString(), "\\r");
			value=((String) value).replace(new Character((char) 9).toString(), "\\t");
			return "\""+value+"\"";
		}
		return this.value.toString();
	}
}
